package com.ruoyi.merchant.service.impl;

import java.util.List;
import java.util.Map;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.db.domain.MerchantBaseInfo;
import com.ruoyi.db.mapper.MerchantBaseInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.db.mapper.MerchantDetailInfoMapper;
import com.ruoyi.db.domain.MerchantDetailInfo;
import com.ruoyi.merchant.service.IMerchantDetailInfoService;

import javax.annotation.Resource;

/**
 * 商户详情信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-09-25
 */
@Service
@DataSource(DataSourceType.SLAVE)
public class MerchantDetailInfoServiceImpl implements IMerchantDetailInfoService 
{
    @Autowired
    private MerchantDetailInfoMapper merchantDetailInfoMapper;

    @Resource
    private MerchantBaseInfoMapper merchantBaseInfoMapper;

    /**
     * 查询商户详情信息
     * 
     * @param infoId 商户详情信息主键
     * @return 商户详情信息
     */
    @Override
    public MerchantDetailInfo selectMerchantDetailInfoByInfoId(Long infoId)
    {
        return merchantDetailInfoMapper.selectMerchantDetailInfoByInfoId(infoId);
    }

    /**
     * 查询商户详情信息列表
     * 
     * @param merchantDetailInfo 商户详情信息
     * @return 商户详情信息
     */
    @Override
    public List<MerchantDetailInfo> selectMerchantDetailInfoList(MerchantDetailInfo merchantDetailInfo)
    {
        return merchantDetailInfoMapper.selectMerchantDetailInfoList(merchantDetailInfo);
    }

    /**
     * 查询商户详情信息列表
     *
     * @param merchantDetailInfo 商户详情信息
     * @return 商户详情信息
     */
    @Override
    public List<Map<String, Object>> selectMerchantDetailInfoMapList(MerchantDetailInfo merchantDetailInfo)
    {
        return merchantDetailInfoMapper.selectMerchantDetailInfoMapList(merchantDetailInfo);
    }

    /**
     * 新增商户详情信息
     * 
     * @param merchantDetailInfo 商户详情信息
     * @return 结果
     */
    @Override
    public int insertMerchantDetailInfo(MerchantDetailInfo merchantDetailInfo)
    {
        merchantDetailInfo.setCreateTime(DateUtils.getNowDate());

        Long infoId = merchantDetailInfo.getInfoId();
        MerchantBaseInfo merchantBaseInfo = merchantBaseInfoMapper.selectMerchantBaseInfoById(infoId);
        merchantDetailInfo.setProductLogo(merchantBaseInfo.getCompanyLogo());
        merchantDetailInfo.setCompanyName(merchantBaseInfo.getCompanyName());

        return merchantDetailInfoMapper.insertMerchantDetailInfo(merchantDetailInfo);
    }

    /**
     * 修改商户详情信息
     * 
     * @param merchantDetailInfo 商户详情信息
     * @return 结果
     */
    @Override
    public int updateMerchantDetailInfo(MerchantDetailInfo merchantDetailInfo)
    {
        merchantDetailInfo.setUpdateTime(DateUtils.getNowDate());
        return merchantDetailInfoMapper.updateMerchantDetailInfo(merchantDetailInfo);
    }

    /**
     * 批量删除商户详情信息
     * 
     * @param infoIds 需要删除的商户详情信息主键
     * @return 结果
     */
    @Override
    public int deleteMerchantDetailInfoByInfoIds(Long[] infoIds)
    {
        return merchantDetailInfoMapper.deleteMerchantDetailInfoByInfoIds(infoIds);
    }

    /**
     * 删除商户详情信息信息
     * 
     * @param infoId 商户详情信息主键
     * @return 结果
     */
    @Override
    public int deleteMerchantDetailInfoByInfoId(Long infoId)
    {
        return merchantDetailInfoMapper.deleteMerchantDetailInfoByInfoId(infoId);
    }
}